package com.thwj.project.biz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.thwj.common.annotation.Log;
import com.thwj.common.core.controller.BaseController;
import com.thwj.common.core.domain.AjaxResult;
import com.thwj.common.core.page.TableDataInfo;
import com.thwj.common.enums.BusinessType;
import com.thwj.common.utils.poi.ExcelUtil;
import com.thwj.project.biz.domain.Banner;
import com.thwj.project.biz.mapper.BannerMapper;
import com.thwj.project.biz.service.IBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 业务-活动bannerController
 *
 * @author generate
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/biz/banner")
public class BannerController extends BaseController {
    @Autowired
    private IBannerService bannerService;

/**
 * 查询业务-活动banner列表
 */
@PreAuthorize("@ss.hasPermi('biz:banner:list')")
@GetMapping("/list")
    public TableDataInfo list(Banner banner) {
        startPage();
        List<Banner> list = bannerService.getBaseMapper().selectList(new QueryWrapper<>(banner).orderByDesc("id"));
        return getDataTable(list,((Page)list).getTotal());
    }

    /**
     * 导出业务-活动banner列表
     */
    @PreAuthorize("@ss.hasPermi('biz:banner:export')")
    @Log(title = "业务-活动banner", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Banner banner) {
        List<Banner> list = bannerService.list(new QueryWrapper<>(banner));
        ExcelUtil<Banner> util = new ExcelUtil<Banner>(Banner. class);
        util.exportExcel(response, list, "业务-活动banner数据");
    }

    /**
     * 获取业务-活动banner详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bannerService.getById(id));
    }

    /**
     * 新增业务-活动banner
     */
    @PreAuthorize("@ss.hasPermi('biz:banner:add')")
    @Log(title = "业务-活动banner", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Banner banner) {
        return toAjax(bannerService.save(banner));
    }

    /**
     * 修改业务-活动banner
     */
    @PreAuthorize("@ss.hasPermi('biz:banner:edit')")
    @Log(title = "业务-活动banner", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Banner banner) {
        return toAjax(bannerService.updateById(banner));
    }

    /**
     * 删除业务-活动banner
     */
    @PreAuthorize("@ss.hasPermi('biz:banner:remove')")
    @Log(title = "业务-活动banner", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bannerService.removeByIds(Arrays.asList(ids)));
    }
}
